﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using System.Web.Script.Serialization;

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service2
{
	// To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
	// To create an operation that returns XML,
	//     add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
	//     and include the following line in the operation body:
	//         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
	[OperationContract]
	public void DoWork()
	{
		// Add your operation implementation here
		return;
	}

    [OperationContract]
    [WebInvoke(Method = "POST",
                BodyStyle = WebMessageBodyStyle.WrappedRequest,
                ResponseFormat = WebMessageFormat.Json
                )]
    public string GetProducts()
    {

        List<object> products = new List<object>();

        for (int i = 1; i < 31; i++)
        {
            products.Add(new
            {
                ProductID = i,
                Name = "Prod" + i.ToString(),
                ProductNumber = i * 123,
                Color = "Color",
                Size = "Size",
                Style = "Style"
            });
        }

        return (new JavaScriptSerializer().Serialize(products));
    }
	// Add more operations here and mark them with [OperationContract]
}
